package com.lm.drools.example;

import com.lm.drools.entry.Product;
import com.lm.drools.service.DiscountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class DroolsTestRunner implements CommandLineRunner {

    @Autowired
    private DiscountService discountService;

    @Override
    public void run(String... args) throws Exception {
        Product goldProduct = new Product();
        goldProduct.setType("GOLD");
        discountService.applyDiscount(goldProduct);
        System.out.println("Gold product discount: " + goldProduct.getDiscount() + "%");

        Product silverProduct = new Product();
        silverProduct.setType("SILVER");
        discountService.applyDiscount(silverProduct);
        System.out.println("Silver product discount: " + silverProduct.getDiscount() + "%");
    }
}
